#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    /**
     * @brief 常规前缀和模拟
     * 
     * @param nums 
     * @return int 
     */
    int minStartValue(vector<int> &nums)
    {
        int n = nums.size();
        vector<int> ansSum(n, 0);
        for (size_t i = 0; i < n; i++)
        {
            if (0 == i)
                ansSum[i] = nums[i];
            else
                ansSum[i] = ansSum[i - 1] + nums[i];
        }
        int ret = 1;

        for (size_t i = 0; i < n; i++)
        {
            while (ansSum[i] + ret < 1)
            {
                ret++;
            }
        }
        return ret;
    }

    int minStartValue_2(vector<int> &nums)
    {
        int nmin = INT_MAX, cur = 0;
        for (int num : nums)
        {
            cur += num;
            nmin = min(nmin, cur);
        }
        return max(1, 1 - nmin);
    }

    int minStartValue_3(vector<int> &nums)
    {
        int low = 0, curr = 0;
        for (auto num : nums)
        {
            curr += num;
            if (num < 0)
                low = min(low, curr);
        }
        return 1 - low;
    }
};
int main()
{
    Solution s;
    vector<int> nums = {-3, 2, -3, 4, 2};
    cout << s.minStartValue_2(nums) << endl;
    return 0;
}